﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices
{
    //BaseTempData
    public partial class BaseTempDataBLL : BaseBll
    {

        private readonly XQ.SP.DalServices.BaseTempDataDal dal = new XQ.SP.DalServices.BaseTempDataDal();
        public BaseTempDataBLL()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsWhere(string whereSql)
        {
            return dal.ExistsWhere(whereSql);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long Id)
        {
            return dal.Exists(Id);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(XQ.SP.Model.BaseTempDataItem model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 批量增加数据
        /// </summary>
        public bool AddList(List<XQ.SP.Model.BaseTempDataItem> models)
        {
            int rows = dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XQ.SP.Model.BaseTempDataItem model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 批量更新数据
        /// </summary>
        public int UpdateList(List<XQ.SP.Model.BaseTempDataItem> models)
        {
            return dal.UpdateList(models);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.BaseTempDataItem GetModel(long Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.BaseTempDataItem GetModelWhereStr(string whereSql)
        {

            return dal.GetModelWhereStr(whereSql);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere = "")
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.BaseTempDataItem> GetModelList(string strWhere = "")
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.BaseTempDataItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='" + datetimeStr + "' ");
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.BaseTempDataItem> DataTableToList(DataTable dt)
        {
            List<XQ.SP.Model.BaseTempDataItem> modelList = new List<XQ.SP.Model.BaseTempDataItem>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XQ.SP.Model.BaseTempDataItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XQ.SP.Model.BaseTempDataItem();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = long.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["TempId"].ToString() != "")
                    {
                        model.TempId = long.Parse(dt.Rows[n]["TempId"].ToString());
                    }
                    model.ImagesPath = dt.Rows[n]["ImagesPath"].ToString();
                    model.T1 = dt.Rows[n]["T1"].ToString();
                    model.T2 = dt.Rows[n]["T2"].ToString();
                    model.T3 = dt.Rows[n]["T3"].ToString();
                    model.T4 = dt.Rows[n]["T4"].ToString();
                    model.T5 = dt.Rows[n]["T5"].ToString();
                    if (dt.Rows[n]["Sort"].ToString() != "")
                    {
                        model.Sort = int.Parse(dt.Rows[n]["Sort"].ToString());
                    }
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = int.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["Creator"].ToString() != "")
                    {
                        model.Creator = long.Parse(dt.Rows[n]["Creator"].ToString());
                    }
                    if (dt.Rows[n]["Created"].ToString() != "")
                    {
                        model.Created = DateTime.Parse(dt.Rows[n]["Created"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }



        /// <summary>
        /// Model的属性对应赋值
        /// </summary>
        public void ModelCopy(XQ.SP.Model.BaseTempDataItem modelOld, XQ.SP.Model.BaseTempDataItem modelNew)
        {

            modelNew.Id = modelOld.Id;

            modelNew.TempId = modelOld.TempId;

            modelNew.ImagesPath = modelOld.ImagesPath;

            modelNew.T1 = modelOld.T1;

            modelNew.T2 = modelOld.T2;

            modelNew.T3 = modelOld.T3;

            modelNew.T4 = modelOld.T4;

            modelNew.T5 = modelOld.T5;

            modelNew.Sort = modelOld.Sort;

            modelNew.Status = modelOld.Status;

            modelNew.Creator = modelOld.Creator;

            modelNew.Created = modelOld.Created;
        }
        #endregion

    }
}